package com.example.demo.repository;

import com.example.demo.entity.News;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.lang.model.element.NestingKind;
import java.util.List;

public interface NewsRepository extends JpaRepository<News, Integer>{
    Page<News> findByTitleContainsOrContentContains(String keywords, PageRequest pageRequest);

    @Query(value = "SELECT n from News n WHERE n.title LIKE CONCAT('%',:keyword,'%') OR n.content LIKE CONCAT('%',:keyword,'%')")
    Page<News> findNewsWithKeywords(@Param("keyword") String keyword, Pageable pageable);
//    Page<News> findAllByTitleLikeOrContentLike(String keywords, Pageable pageable);

}
